package com.ruoyi.web.controller.zzwt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.zzw.LongListDto;
import com.ruoyi.common.core.domain.zzw.TEventManage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITEventManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件Controller
 *
 * @author xbx
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/system/event")
public class TEventManageController extends BaseController {
    @Autowired
    private ITEventManageService tEventManageService;

    /**
     * 查询事件列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEventManage tEventManage) {
        startPage();
        List<TEventManage> list = tEventManageService.selectTEventManageList(tEventManage);
        return getDataTable(list);
    }

    /**
     * 导出事件列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TEventManage tEventManage) {
        List<TEventManage> list = tEventManageService.selectTEventManageList(tEventManage);
        ExcelUtil<TEventManage> util = new ExcelUtil<TEventManage>(TEventManage.class);
        util.exportExcel(response, list, "事件数据");
    }

    /**
     * 获取事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{cEventId}")
    public AjaxResult getInfo(@PathVariable("cEventId") Long cEventId) {
        return success(tEventManageService.selectTEventManageByCEventId(cEventId));
    }

    /**
     * 新增事件
     */
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "事件", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody TEventManage tEventManage) {
        return toAjax(tEventManageService.insertTEventManage(tEventManage));
    }

    /**
     * 修改事件
     */
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "事件", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody TEventManage tEventManage) {
        return toAjax(tEventManageService.updateTEventManage(tEventManage));
    }

    /**
     * 删除事件
     */
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/batchDelete")
    public AjaxResult remove(@RequestBody LongListDto cTagIds) {
        return toAjax(tEventManageService.deleteTEventManageByCEventIds(cTagIds.getIds()));
    }

    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping("/trackEvent/{}")
    public AjaxResult getEventTrack(@RequestBody LongListDto cTagIds) {
        return toAjax(tEventManageService.deleteTEventManageByCEventIds(cTagIds.getIds()));
    }
}
